package a00_LeetCode.Set;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author quan
 * @Description 宝石与石头
 * @Date 2023/4/5 19:44
 */
public class Num771_numJewelsInStones {
    public int numJewelsInStones(String jewels, String stones) {
        //先遍历jewels字符串，取出里面的宝石类型存储到Set接口中
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < jewels.length(); i++) {
            set.add(jewels.charAt(i));
        }
        //再遍历stones字符串，判断里面的每个字符是否是Set中的宝石类型：是的话计数器+1，否则不操作
        int num = 0;
        for (int i = 0; i < stones.length(); i++) {
            if(set.contains(stones.charAt(i))){
                num++;
            }
        }
        return num;
    }
}
